core/rawdb: fix datarace in freezer #22728
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #22714 .
The Append / truncate operations were racy. When a datafile reaches
2Gb
, a new file is needed. For this operation, we require a writelock, which is not needed in the 99.99% of all cases where the data does fit in the current head-file.This transition from readlock to writelock was incorrect, and as the readlock was released, a
truncate
operation could slip in between, and truncate the data. This would have been fine, however, theAppend
operation continued writing as if no truncation had occurred, e.g writing item5
where item0
should reside.This PR changes the behaviour, so that if when we run into the situation that a new file is needed, it aborts, and retries, this time with a writelock.
The outcome of the situation described above, running on this PR, would instead be that the
Append
operation exits with a failure.The attached testcase, when enabled, finds the (original) bug pretty quickly.